/**   
* @Title: PayBillServiceImpl.java 
* @Package cn.kxm.service.impl 
* @Description: TODO(用一句话描述该文件做什么) 
* @author 初雨泽
* @date 2018年9月27日 下午2:35:15   
*/
package cn.kxm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.kxm.dao.InstroageBillDao;
import cn.kxm.dao.PayBillDao;
import cn.kxm.dao.PayBillDetailDao;
import cn.kxm.pojo.Company;
import cn.kxm.pojo.PayBill;
import cn.kxm.pojo.PayBillDetail;
import cn.kxm.service.PayBillService;

/** 
* @ClassName: PayBillServiceImpl 
* @Description: paybill的服务实现类
* @author 初雨泽
* @date 2018年9月27日 下午2:35:15 
*  
*/
@Service
public class PayBillServiceImpl implements PayBillService{
	
	@Autowired
	PayBillDao payBillDao;
	
	@Autowired
	PayBillDetailDao payBillDetailDao;
	
	@Autowired
	InstroageBillDao instroageBillDao;

	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#searchPayBill(java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public List<PayBill> searchPayBill(Integer page, Integer rows, String findcode, String findstartDate,
			String findendDate, String findsupplierName) {
		return payBillDao.searchPayBill(((page-1)*rows), rows, findcode, findstartDate, findendDate, findsupplierName);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#countSearchPayBill(java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public int countSearchPayBill (String findcode, String findstartDate, String findendDate,
			String findsupplierName) {
		return payBillDao.countSearchPayBill(findcode, findstartDate, findendDate, findsupplierName);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#deletePayBillByCode(java.lang.String)
	 */
	@Override
	public void deletePayBillByCode(String code) {
		payBillDao.deletePayBillByCode(code);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#searchCompany(java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.Integer)
	 */
	@Override
	public List<Company> searchCompany(String code, String name, Integer type, Integer page, Integer rows) {
		return payBillDao.searchCompany(code, name, type, ((page-1)*rows), rows);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#countSearchCompany(java.lang.String, java.lang.String, java.lang.Integer)
	 */
	@Override
	public int countSearchCompany(String code, String name, Integer type) {
		return payBillDao.countSearchCompany(code, name, type);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#findPayBill(java.lang.String)
	 */
	@Override
	public PayBill findPayBill(String code) {
		return payBillDao.findPayBill(code);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#updatePayBillType(java.lang.String, java.lang.Integer)
	 */
	@Override
	public void updatePayBillType(String code, Integer type) {
		payBillDao.updatePayBillType(code, type);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#updatePayBill(java.lang.String, java.lang.Integer, java.lang.String, java.lang.String)
	 */
	@Override
	public void updatePayBill(String payData, Integer payType, String memo, String code,Float payTotalMoney) {
		System.out.println("payTotal_f:"+payTotalMoney);
		payBillDao.updatePayBill(payData, payType, memo, code, payTotalMoney);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#addPayBill(cn.kxm.pojo.PayBill)
	 */
	@Override
	public void addPayBill(PayBill paybill) {
		payBillDao.addPayBill(paybill);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#deletePayBillUnchecked(java.lang.String)
	 */
	@Override
	public void deletePayBillUnchecked(String payCode) {
		payBillDetailDao.deleteDetailListByPayBill(payCode);
		payBillDao.deletePayBill(payCode);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#deletePayBillChecked(java.lang.String)
	 */
	@Override
	public void deletePayBillChecked(String payCode) {
		List<PayBillDetail> payBillDetailList= payBillDetailDao.findPayBillDetail(payCode);
		for (PayBillDetail a:payBillDetailList) {
			instroageBillDao.updateInstroageBillType(a.getBillCode(), 1);
		}
		payBillDetailDao.deleteDetailListByPayBill(payCode);
		payBillDao.deletePayBill(payCode);
	}
	/* (non-Javadoc)
	 * @see cn.kxm.service.PayBillService#findAllPayBill()
	 */
	@Override
	public List<PayBill> findAllPayBill(String findcode,
			String findstartDate,
			String findendDate,
			String findsupplierName) {
		return payBillDao.findAllPayBill(findcode, findstartDate, findendDate, findsupplierName);
	}

}
